1. Field of the Invention
The present invention relates to an optimizing method and apparatus for a compiler, and particularly, to an optimizing compiler that compiles a source program language into an optimized assembler language or a machine code.
2. Description of the Related Art
Computer hardware systems have been developed to improve operation speed.
To improve the execution speed of a program, a compiler carries out optimization when compiling the program. Japanese Patent Application No. 4-004869 discloses an optimization technique applicable for optimizing conditional branch statements described in a program. This technique selects instructions to be used, according to the true rate of a corresponding conditional branch statement. This technique is not designed to stop the execution of a statement even if the statement is unnecessary.
Another prior art system moves an invariant conditional branch statement contained in a loop outside the loop, to reduce the number of conditional decisions to be made in the loop. This prior art system aims to reduce the number of conditional decisions to be made in a loop without reducing other operations.
The compiler compiles a source program written in a programming language such as C, FORTRAN, or COBOL into an object program written in a second language such as an assembler language. Optimization carried out by the compiler when compiling the source program into the object program is intended to shorten the execution time of the object program without changing the meaning of the source program. The compiler optimizes the program by integrating the same operations into one or by suppressing unnecessary operations.
When writing a program, a programmer frequently employs redundant operations to simplify the program and assure the correctness of the program. These redundant operations are still left in an object program and elongate the execution time of the program, because conventional compilers do not move or insert conditional branch statements when optimizing the program.
If a program involves a repetition of unnecessary operations, it will slow the execution speed of the program. It is required, therefore, to provide an optimizing compiler that is capable of finding unnecessary operations related to conditional branch statements described in a program and shortening the execution time of the program.